﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;

namespace Seminarska
{
    /// <summary>
    /// Interaction logic for BrisiPlus.xaml
    /// </summary>
    public partial class BrisiPlus : Window
    {

        public BrisiPlus()
        {
            InitializeComponent();
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection konekcija = new SqlConnection();
            konekcija.ConnectionString = Seminarska.Properties.Settings.Default.Products;
            SqlCommand komanda = new SqlCommand();
            komanda.Connection = konekcija;

            bool flag = false;
            string kod = txtKod.Text;
            komanda.CommandText = "SELECT Kod FROM Produkti";

            try
            {
                konekcija.Open();
                SqlDataReader citac = komanda.ExecuteReader();

                while (citac.Read())
                {
                    if (citac["Kod"].ToString() == kod)
                        flag = true;

                }
                citac.Close();
            }
            catch (Exception err)
            {
                //lblMessage.Text = err.Message;
            }
            finally
            {
                konekcija.Close();
            }

            if (flag == true)
            {

                komanda.CommandText = "DELETE FROM Produkti WHERE Kod=@Kod";
                komanda.Parameters.AddWithValue("@Kod", kod);


                try
                {
                    konekcija.Open();
                    komanda.ExecuteNonQuery();
                }
                catch (Exception err)
                {
                    // lblPoraka.Text = err.Message;
                }
                finally
                {
                    konekcija.Close();
                   
                    
                    this.Close();
                }
            }
            else MessageBox.Show("Се обидувате да избришете продукт со непостоечки код!!!");
        }

        private void Window_Closed(object sender, EventArgs e)
        {
           
            
                
        }
    }
}
